package com.zhuangjie.rider.mq.producer.config;

import com.zhuangjie.rabbit.config.wrap.ExchangeWrap;
import com.zhuangjie.rabbit.config.wrap.MQStructureConfig;
import com.zhuangjie.rider.constant.DeliveryOrderConstant;
import com.zhuangjie.rider.mq.producer.event.DeliveryOrderEvent;
import com.zhuangjie.rider.mq.producer.structure.DeliveryOrderMQStructure;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Component
public class OrderMQStructureConfig implements MQStructureConfig {

    @Override
    public List<ExchangeWrap> exchangeWrap() {
        ExchangeWrap exchangeWrap = new ExchangeWrap(ExchangeBuilder.topicExchange(DeliveryOrderMQStructure.EXCHANGE_NAME).durable(true).build())
                .to(DeliveryOrderEvent.ORDER_ACCEPTANCE_TIMEOUT, QueueBuilder.durable(DeliveryOrderMQStructure.Queues.CANCEL_ORDER_LOCK_QUEUE).build(), TimeUnit.SECONDS.toMillis(DeliveryOrderConstant.ORDER_ACCEPTANCE_TIMEOUT));
        return Arrays.asList(exchangeWrap);
    }

}
